package com.tjetc.view.teacherview;

import com.tjetc.proxy.CilentProxy;
import com.zhiyun.domain.Course;
import com.zhiyun.domain.Notice;
import com.zhiyun.service.NoticeService;
import com.zhiyun.vo.Result;

import java.util.List;
import java.util.Scanner;

public class MyCourseView_In_Notice {
    NoticeService noticeService= CilentProxy.getProxyInstance(NoticeService.class);
    Scanner scanner=new Scanner(System.in);
    public void start(Course course){
        while (true){
            System.out.println("通知");
            System.out.println("1. 查看通知列表");
            System.out.println("2. 发布通知");
            System.out.println("0. 返回上一级");
            int i = scanner.nextInt();
            switch (i){
                case 1:
                    allNotice(course);
                    break;
                case 2:
                    insertNotice(course);
                    break;
                case 0:
                    return;
                default:
                    break;
            }
        }
    }

    private void allNotice(Course course) {
        while (true){
            Result byCourseId = noticeService.findByCourseId(course.getId());
            if (byCourseId.getCode()==200){
                List<Notice> obj = (List<Notice>) byCourseId.getObj();
                for (Notice notice : obj) {
                    System.out.println("通知id"+notice.getId()+"      通知内容:"+notice.getMessage());
                }
            }
            break;
        }
    }

    private void insertNotice(Course course) {
        while (true){
            System.out.println("请输入通知内容");
            String message = scanner.next();
            Notice notice = new Notice(null, message, course.getId());
            Result result = noticeService.insertNotice(notice);
            if (result.getCode()==200){
                System.out.println(result.getMsg());
            }else {
                System.out.println(result.getMsg());
            }
            break;
        }
    }
}
